class BigWin extends egret.DisplayObjectContainer {
    money: number;
    private context:GunDeal;
    private speed = .1;
    private eWidth: number;
    private eHeight: number;

    private ii: any;

    public constructor(context: any) {
        super();
        this.context = context;
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
    }

    public setMoney(money: number) {
        this.money = money;
    }

    private onAddToStage(event: egret.Event) {
        this.removeEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
        new Bg(this, 'mark_in_free_png');
        var percentage = 0.65;
        this.touchEnabled = true;
        this.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClose, this);

        //加载主面板
        var imgCon = [];
        imgCon['url'] = 'big_win_bg_png';
        imgCon['width'] = this.stage.stageWidth * 0.4;
        imgCon['height'] = this.stage.stageHeight * 0.4;
        imgCon['y'] = (this.stage.stageHeight - imgCon['height']) / 2;
        imgCon['x'] = (this.stage.stageWidth - imgCon['width']) / 2;
        this.addChild(new ImageBitmap(imgCon).getImgPoint());


        /**
         * 钱的标志
         */
        var moneySign = [];
        moneySign['url'] = 'money_sign_png';
        moneySign['width'] = this.stage.stageWidth * 0.025;
        moneySign['height'] = this.stage.stageHeight * 0.032 * 1920 / 1080;
        moneySign['y'] = this.stage.stageHeight * 0.618;
        moneySign['x'] = this.stage.stageWidth * 0.318;
        this.addChild(new ImageBitmap(moneySign).getImgPoint());

        /**
             * 后面一串钱
             */
        var tempNumber: number = this.money;
        var showNumber: number = 0;
        var numberlist = Array();
        var numTmp = this.money.toString();
        var numArr = [];
        for (var i = numTmp.length - 1; i > -1; i--) {
            numArr.push(numTmp.charAt(i));
        }
        for (var i = 0; i < 20; i++) {
            numArr.push("0");
        }
        for (var i = 0; i < 11; i++) {
            showNumber = numArr[i];
            numberlist = Array();
            numberlist['url'] = "p_" + showNumber + '_png';
            numberlist['width'] = this.stage.stageWidth * 0.02;
            numberlist['height'] = this.stage.stageHeight * 0.03 * 1920 / 1080;
            numberlist['y'] = this.stage.stageHeight * 0.62;
            numberlist['x'] = this.stage.stageWidth * (0.607 - i * 0.026);
            this.addChild(new ImageBitmap(numberlist).getImgPoint());
            // tempNumber = Math.floor(tempNumber / 10);
        }

        this.alpha = 0;
        var am = new Am(600,600,"TG_000");
        am.x += 220;
        am.y -= 40;
        this.addChild(am);
       this.openAm();

        this.context.context.soundctr.playSound("gold_coin_mp3");
        //自动关闭 界面
        var point = this;
        setTimeout(function () {
            point.onClose();
        }, 2500);
    }

    public openAm(): void {
        this.removeEventListener(egret.Event.ENTER_FRAME, this.enterFrameHandler, this);
        this.addEventListener(egret.Event.ENTER_FRAME, this.enterFrameHandler, this);
    }
    public closeAm(): void {
        this.removeEventListener(egret.Event.ENTER_FRAME, this.closeFrameHandler, this);
        this.addEventListener(egret.Event.ENTER_FRAME, this.closeFrameHandler, this);
    }
    /**打开时逐帧运动*/
    private enterFrameHandler(event: egret.Event): void {
        if (this.alpha < 1) {
            this.alpha += this.speed;
        } else {
            this.pauseOpenAm();
        }
    }

    /**
     * 关闭时动画运动
     * @param event
     */
    private closeFrameHandler(event: egret.Event): void {
        if (this.alpha > 0) {
            this.alpha -= this.speed;
        } else {
            this.pauseOpenAm();
            if (this.parent) {
                this.parent.removeChild(this);
                this.context.complete();
            }
        }
    }
    /**暂停打开时动画*/
    public pauseOpenAm(): void {
        this.removeEventListener(egret.Event.ENTER_FRAME, this.enterFrameHandler, this);
    }

    /**暂停关闭时的动画*/
    public pauseCloseAm(): void {
        this.removeEventListener(egret.Event.ENTER_FRAME, this.closeFrameHandler, this);
    }

    private onClose() {
        if (this.alpha < 1) {
            return;
        }
        this.closeAm();
    }
}